#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time   : 2022/4/22 14:49
# @Author : chenlq
from poium.common import logging

builtin_str = str
basestring = (str, bytes)
integer_types = (int,)


@logging.logger.catch
def assert_compare(r1, compare, r2):
    """判断是否相等"""
    logging.info("预期结果: {} {} {}".format(r1, compare, r2))
    try:
        if compare == "==":
            assert r1 == r2
        elif compare == "<":
            assert r1 < r2
        elif compare == ">":
            assert r1 > r2
        elif compare == "!=":
            assert r1 != r2
        elif compare == "in":
            assert r1 in r2
        else:
            try:
                raise NameError("{} 断言方式错误，请填写正确的运算符".format(compare))
            except Exception as e:
                logging.logger.exception(e)
                raise
        logging.info("断言成功!")
    except AssertionError as e:
        logging.logger.exception("断言失败: {}".format(e))
        raise


def startswith(check_value, r2):
    """检查开头是否和预期结果内容的开头相等"""
    assert builtin_str(check_value).startswith(builtin_str(r2))


def endswith(check_value, r2):
    """检查结尾是否和预期结果内容相等"""
    assert builtin_str(check_value).endswith(builtin_str(r2))
